/**
 * 
 */
package os.filesystem.tool;

import java.util.Stack;

import os.filesystem.file.Directory;
import os.filesystem.file.RootDirectory;
import os.filesystem.storage.DiskIO;
import os.filesystem.storage.IO;
import os.filesystem.utils.FSProperties;

/**
 * This static class holds the state for the user.
 * 
 * @author Raghav Sidhanti
 * @since Mar 6, 2012 10:50:07 AM
 *
 */
public class FSState {
	
	private static Stack<Directory> workingDirStack = null; 
	static Directory rootDir = null;
	static IO io = null;
	
	public static String user;
	
	static {
		flush();
	}
	/**
	 * Flushes the entire state of the system.
	 */
	static void flush(){
		workingDirStack = new Stack<Directory>();
		rootDir = new RootDirectory(FSProperties.getProperty(FSProperties.FILE_ROOT), FSProperties.getProperty(FSProperties.USER_SYSTEM));
		io = new DiskIO(FSProperties.getProperty(FSProperties.DISK_LOCATION));
		workingDirStackPush(rootDir);
		user = FSProperties.getProperty(FSProperties.USER_LOGIN);
	}
	
	static void workingDirStackPush(Directory dir){
		workingDirStack.push(dir);
	}
	
	static Directory workingDirStackPop(){
		if(workingDirStack.size() == 1){
			return workingDir();
		}
		return workingDirStack.pop();
	}
	
	static Directory workingDir(){
		return workingDirStack.peek();
	}
}